package com.jr.daoimpl;

import com.jr.dao.EnterpriseDao;
import com.jr.entity.Enterprise;
import com.jr.pojo.EnterpriseName;
import com.jr.pojo.SocialCode;
import util.DBHelper;

import java.util.ArrayList;


public class EnterpriseDaoImpl implements EnterpriseDao{
    DBHelper db = new DBHelper();



    @Override
    public int addEnterprise(String enamess, String social_uniform_code, String email, String ephone, String address, String scale, String fax) {
        String sql = "insert into enterprise(enamess,social_uniform_code,email,ephone,address,scale,fax) values(?,?,?,?,?,?,?) ";
        Object[] objects = {enamess,social_uniform_code,email,ephone,address,scale,fax};
        return db.update(sql,objects);
    }

    @Override
    public Enterprise selectAll(String enamess) {
        String sql = "select * from enterprise where enamess=?";
        ArrayList<Enterprise> list = db.query(sql,Enterprise.class,enamess);
        if(list.size()>0){
            return (Enterprise)list.get(0);
        }else{
            return null;
        }
    }


    @Override
    public ArrayList<SocialCode> selectCode() {
        String sql = "select enamess,social_uniform_code from enterprise";
        return db.query(sql,SocialCode.class);
    }


    @Override
    public ArrayList selectAllName(int eid) {
        String sql = "select enamess from enterprise where eid!=?";
        return db.query(sql, EnterpriseName.class,eid);
    }
}
